package observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 主题具体实现类
 */
public class WeatherData implements Subject{
    private float humidity;
    private float pressure;
    //观察者列表
    private final List<Observer> observers=new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.forEach(ele->ele.update(humidity,pressure));
    }

    public void setWeather(float humidity,float pressure){
        this.humidity=humidity;
        this.pressure=pressure;
        notifyObservers();
    }
}
